package com.five.controller.backstage;

import com.alibaba.fastjson.JSON;
import com.five.dao.backstage.RoomDao;
import com.five.dao.impl.backstage.RoomDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: 王登峰
 * @Description:
 * @Date: 2020/11/12 19:53
 */
@WebServlet("/room")
public class RoomController extends RoleController {
    RoomDao roomDao  = new RoomDaoImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        String method = req.getParameter("method");
        switch (method){
            case "select":
                select(req,resp);
        }

    }
    public void select(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        List<Map> list = roomDao.selectRoom();
        Map map  = new HashMap();
        map.put("code",0);
        map.put("msg","");
        map.put("count",3000);
        map.put("data",list);
        String s = JSON.toJSONString(map);
        PrintWriter out = resp.getWriter();
        out.write(s);
        out.flush();
        out.close();
    }
}
